package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.PaymentSheetTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.fund.enums.PayMethodDistributorEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.PaymentSheetDistributorEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 * @author zcp
 */
@Getter
public enum TempPaymentSheetDistributorEnum {

    //刷脚本专用枚举
    BASE_INFO(PaymentSheetDistributorEnum.BASE_INFO),
    PAYMENT_SHEET_TYPE(PaymentSheetDistributorEnum.PAYMENT_SHEET_TYPE),
    SHEET_NO(PaymentSheetDistributorEnum.SHEET_NO),
    DISTRIBUTOR_ID(PaymentSheetDistributorEnum.DISTRIBUTOR_ID),
    ORDER(PaymentSheetDistributorEnum.ORDER),
    PAYMENT(PaymentSheetDistributorEnum.PAYMENT),
    AMOUNT(PaymentSheetDistributorEnum.AMOUNT),
    WRITE_OFF_AMOUNT(PaymentSheetDistributorEnum.WRITE_OFF_AMOUNT),
    INVOICE_AMOUNT(PaymentSheetDistributorEnum.INVOICE_AMOUNT),
    BELONG_ID(PaymentSheetDistributorEnum.BELONG_ID),
    PAYMENT_TIME(PaymentSheetDistributorEnum.PAYMENT_TIME),
    FUND_ACCOUNT(PaymentSheetDistributorEnum.FUND_ACCOUNT),
    PAY_METHOD(PaymentSheetDistributorEnum.PAY_METHOD),
    SYSTEM_INFO(PaymentSheetDistributorEnum.SYSTEM_INFO),
    PAYMENT_TASK(PaymentSheetDistributorEnum.PAYMENT_TASK),
    ONLINE_PAYMENT_FLOW(PaymentSheetDistributorEnum.ONLINE_PAYMENT_FLOW),
    PAYER(PaymentSheetDistributorEnum.PAYER),
    PAYER_ID(PaymentSheetDistributorEnum.PAYER_ID),
    MEMO(PaymentSheetDistributorEnum.MEMO),
    FILE(PaymentSheetDistributorEnum.FILE),
    RED_SHEET(PaymentSheetDistributorEnum.RED_SHEET),
    CREATOR_ID(PaymentSheetDistributorEnum.CREATOR_ID),
    ADD_TIME(PaymentSheetDistributorEnum.ADD_TIME),
    UPDATE_TIME(PaymentSheetDistributorEnum.UPDATE_TIME),
    OWNER_ID(PaymentSheetDistributorEnum.OWNER_ID),
    COUSERID(PaymentSheetDistributorEnum.COUSERID),

    DISTRIBUTOR_NAME_LINK_TEXT(PaymentSheetDistributorEnum.DISTRIBUTOR_NAME_LINK_TEXT),
    ORDER_LINK_TEXT(PaymentSheetDistributorEnum.ORDER_LINK_TEXT),
    PAYMENT_LINK_TEXT(PaymentSheetDistributorEnum.PAYMENT_LINK_TEXT),
    RED_SHEET_LINK_TEXT(PaymentSheetDistributorEnum.RED_SHEET_LINK_TEXT),
    PAYMENT_TASK_LINK_TEXT(PaymentSheetDistributorEnum.PAYMENT_TASK_LINK_TEXT),
    ONLINE_PAYMENT_FLOW_LINK_TEXT(PaymentSheetDistributorEnum.ONLINE_PAYMENT_FLOW_LINK_TEXT),
    ;
    private PaymentSheetDistributorEnum anEnum;

    TempPaymentSheetDistributorEnum(PaymentSheetDistributorEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempPaymentSheetDistributorEnum> getAllEnum() {
        List<TempPaymentSheetDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initPaymentSheetType(FieldAttrEntity fieldAttrEntity){
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(PaymentSheetTypeEnum.class, fieldAttrEntity.getFieldType());
        for (ItemPoJo itemPoJo : itemPoJoList) {
            itemPoJo.setNoEdit(BasicConstant.ONE);
            itemPoJo.setNoMove(BasicConstant.ONE);
        }
        fieldAttrEntity.setItems(itemPoJoList);
        fieldAttrEntity.setDictionaryFlag(BasicConstant.TWO);
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setNoItemLink(BasicConstant.ONE);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
    }

    public static void initSheetNo(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.PAYMENT_SHEET.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.PAYMENT_SHEET.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.PAYMENT_SHEET_NO));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    /**
     * 初始化关联客户
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     * @author 徐俊杰
     * @date 2019/11/18 16:18
     * @since v1.0
     */
    public static void initDistributorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(DISTRIBUTOR_NAME_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initOrder(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.CONTRACT.getCode());
        fieldAttrEntity.setLinkedText(ORDER_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyAttr(DISTRIBUTOR_ID.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setBusinessType(XbbRefTypeEnum.PAYMENT_SHEET.getCode());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initPayment(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PAYMENT.getCode());
        fieldAttrEntity.setLinkedText(PAYMENT_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyAttr(ORDER.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CONTRACT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initFile(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initRedSheet(FieldAttrEntity fieldAttrEntity) {
        //改为回款单类型，因为打开关联原始回款单详情的时候，是要用回款单的type去得到tab、button等（通过data内的回款单类型来区分具体哪种类型的回款单）
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PAYMENT_SHEET.getCode());
        fieldAttrEntity.setLinkedText(RED_SHEET_LINK_TEXT.getAnEnum().getAttr());
        fieldAttrEntity.setBusinessType(XbbRefTypeEnum.PAYMENT_SHEET.getCode());
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        //不允许修改默认值
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initWriteOffAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        //不允许修改默认值
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initInvoiceAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_DEFAULT.getAlias()));
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initBelongId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initPaymentTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType( DateTimeEnum.TIME.getType());
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("today");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
    }

    public static void initFundAccount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDictionaryFlag(BasicConstant.TWO);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setNoItemLink(BasicConstant.ONE);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
        fieldAttrEntity.setMemo("账户信息可在【管理中心-其他设置-资金账户】中自定义修改");
    }

    public static void initPayMethod(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(PayMethodDistributorEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(BasicConstant.TWO);
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setNoItemLink(BasicConstant.ONE);
        fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
        fieldAttrEntity.setShowAttrPermission(BasicConstant.ZERO);
    }

    public static void initPaymentTask(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.PAYMENT_TASK.getCode());
        fieldAttrEntity.setLinkedText(PAYMENT_TASK_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyAttr(ORDER.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CONTRACT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }
    public static void initOnlinePaymentFlow(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.ONLINE_PAYMENT_FLOW.getCode());
        fieldAttrEntity.setLinkedText(ONLINE_PAYMENT_FLOW_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        /*
        saasParticularAttributePoJo.setRelyAttr(ORDER.anEnum.getAttr());
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.CONTRACT.getCode());
        */
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initPayer(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setLinkedText(PAYER_ID.getAnEnum().getAttr());
        fieldAttrEntity.setEditable(BasicConstant.ZERO);
        fieldAttrEntity.setEditForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setShowEditable(BasicConstant.ZERO);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.DISTRIBUTOR_ADD));
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(1);
    }
}
